package ui.panel.trains
{

	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	import globals.ButtonType;
	import globals.Global;

	import ui.component.Button;
	import ui.component.Label;
	import ui.component.ScaleBitmap;
	import ui.component.TextButton;
	import ui.face.Bar;

	import util.TextStyle;
	import util.UIUtil;

	/**
	 * 英雄的信息。
	 * @author luguobin
	 */
	public class TrainWarriorInfo extends Sprite
	{
		private var _roleImg:Bitmap;
		private var _txtItems:Vector.<TextField> = new Vector.<TextField>;
		private var _expBar:Bar; //经验

		public function TrainWarriorInfo()
		{
			super();
			addBg();
			initContent();
		}

		private function addBg():void
		{
			var bg:ScaleBitmap = new ScaleBitmap(Global.assetsManager.getAssetsAsBitmapData("tower_bg"));
			bg.scale9Grid = new Rectangle(35, 35, 14, 14);
			bg.width = 150;
			bg.height = 335;
			this.addChild(bg);
		}

		private function initContent():void
		{
			_roleImg = new Bitmap(Global.assetsManager.getAssetsAsBitmapData("avatar_1_1", "warrior"));
			_roleImg.x = (this.width - _roleImg.width) / 2;
			_roleImg.y = 15;
			this.addChild(_roleImg);
			var txtX:Array = [0, 0, 45, 80, 45, 80, 45, 80, 0];
			var txtY:Array = [115, 135, 185, 185, 205, 205, 225, 225, 265];

			for(var i:int = 0; i < 9; i++)
			{
				var myTxt:TextField = new TextField();
				myTxt.selectable = false;

				if(i == 0)
				{
					myTxt.width = 150;
					myTxt.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, true, "center");
				}
				else if(i == 1 || i == 8)
				{
					myTxt.width = 150;
					myTxt.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, false, "center");
				}
				else
				{
					myTxt.defaultTextFormat = TextStyle.getTextFormat();
					myTxt.autoSize = TextFieldAutoSize.LEFT;
				}
				myTxt.x = txtX[i];
				myTxt.y = txtY[i];
				myTxt.height = 18;
				this.addChild(myTxt);
				_txtItems.push(myTxt);
			}
			TextStyle.addTextFrame(_txtItems[3], 0x653011);
			TextStyle.addTextFrame(_txtItems[5], 0x653011);
			TextStyle.addTextFrame(_txtItems[7], 0x653011);
			_expBar = new Bar("experience_front", "experience_bg", true);
			_expBar.x = 16;
			_expBar.y = 160;
			this.addChild(_expBar);

			var addBtn:Button = UIUtil.getButton(0, ButtonType.BUTTON_ADD, btnHandle);
			addBtn.x = 111;
			addBtn.y = 262;
			this.addChild(addBtn);

			var heroListBtn:TextButton = UIUtil.getTextButton(1, "英雄列表", ButtonType.BUTTON_YELLOW, btnHandle);
			heroListBtn.x = 40;
			heroListBtn.y = 290;
			this.addChild(heroListBtn);

			update(new Object); //测试
		}

		private function btnHandle(btn:Button):void
		{
			if(btn.id == 0)
			{

			}
			else if(btn.id == 1)
			{
				Global.uiManager.trainPanel.popUpHeroList();
			}
		}

		public function update(obj:Object):void
		{
			_txtItems[0].text = "英雄名字";
			_txtItems[1].text = "弓箭手 lv.2";
			_txtItems[2].text = "武力:";
			_txtItems[3].text = "100";
			_txtItems[4].text = "魔力:";
			_txtItems[5].text = "123";
			_txtItems[6].text = "内政:";
			_txtItems[7].text = "145";
			_txtItems[8].text = "训练队列 3/5";
			_expBar.update(30, 100);
		}
	}
}